package com.zqxq.lottery.service.user.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.zqxq.lottery.common.constant.HuaYangConstant;
import com.zqxq.lottery.config.YmlConfig;
import com.zqxq.lottery.entity.bo.user.UserMsgBO;
import com.zqxq.lottery.entity.vo.user.UserMsgVO;
import com.zqxq.lottery.mapper.user.UserInfoMapper;
import com.zqxq.lottery.mq.Sender;
import com.zqxq.lottery.service.user.IUserMsgService;
import com.zqxq.lottery.entity.po.user.UserMsgPO;
import com.zqxq.lottery.mapper.user.UserMsgMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;


@Service
@Slf4j
public class UserMsgServiceImpl extends ServiceImpl<UserMsgMapper,UserMsgPO> implements IUserMsgService {

    @Autowired
    private YmlConfig ymlConfig;
    @Autowired
    private UserInfoMapper userInfoMapper;
    @Autowired
    private IUserMsgService userMsgService;
    @Autowired
    private Sender sender;

    @Override
    public Page<UserMsgVO> queryPageList(UserMsgBO search) {
        Page page = new Page(search.getPageNo(), search.getPageSize());
        List<UserMsgVO> list = baseMapper.queryPage(page, search);
        page.setRecords(list);
        baseMapper.updateStatus(search);
        return page;
    }

    @Override
    public int queryUserMsgNew(String userId) {
        return baseMapper.queryUserMsgNew(userId);
    }

    public void saveUserMsg(Long userId, String content, Integer type){
        UserMsgPO po = new UserMsgPO();
        po.setId(ymlConfig.getPkId());
        po.setUser_id(userId);
        po.setContent(content);
        po.setType(type);
        po.setStatus(0);
        baseMapper.insert(po);
    }

    @Override
    public void insertBatchMsg(String content) {
        sender.send(HuaYangConstant.MQ_BATCH_INSERT_MSG,content);
    }
}
